part of '../controller.dart';

class _SubscriptionNotificationDataDto extends Equatable implements _NotificationDataDto {
  const _SubscriptionNotificationDataDto._internal({
    required this.typeCode,
    required this.purchaseToken,
    required this.purchaseItemSku,
  });

  final int typeCode;
  final String purchaseToken;
  final String purchaseItemSku;

  @override
  List<Object?> get props {
    return [
      typeCode,
      purchaseToken,
      purchaseItemSku,
    ];
  }

  factory _SubscriptionNotificationDataDto.fromJson(Map<String, dynamic> json) {
    return _SubscriptionNotificationDataDto._internal(
      typeCode: json['notificationType'],
      purchaseToken: json['purchaseToken'],
      purchaseItemSku: json['subscriptionId'],
    );
  }

  @override
  GooglePlayApiSubscriptionNotificationData toEntity() {
    late final GooglePlayApiSubscriptionNotificationType type;

    if (typeCode == 1) {
      type = GooglePlayApiSubscriptionNotificationType.recovered;
    } else if (typeCode == 2) {
      type = GooglePlayApiSubscriptionNotificationType.renewed;
    } else if (typeCode == 3) {
      type = GooglePlayApiSubscriptionNotificationType.canceled;
    } else if (typeCode == 4) {
      type = GooglePlayApiSubscriptionNotificationType.purchased;
    } else if (typeCode == 5) {
      type = GooglePlayApiSubscriptionNotificationType.onHold;
    } else if (typeCode == 6) {
      type = GooglePlayApiSubscriptionNotificationType.inGracePeriod;
    } else if (typeCode == 7) {
      type = GooglePlayApiSubscriptionNotificationType.restarted;
    } else if (typeCode == 8) {
      type = GooglePlayApiSubscriptionNotificationType.priceChangeConfirmed;
    } else if (typeCode == 9) {
      type = GooglePlayApiSubscriptionNotificationType.deferred;
    } else if (typeCode == 10) {
      type = GooglePlayApiSubscriptionNotificationType.paused;
    } else if (typeCode == 11) {
      type = GooglePlayApiSubscriptionNotificationType.pauseScheduleChanged;
    } else if (typeCode == 12) {
      type = GooglePlayApiSubscriptionNotificationType.revoked;
    } else if (typeCode == 13) {
      type = GooglePlayApiSubscriptionNotificationType.expired;
    }

    return GooglePlayApiSubscriptionNotificationData(
      purchaseToken: purchaseToken,
      purchaseItemSku: purchaseItemSku,
      type: type,
    );
  }
}
